
#include "Flyweight.h"
#include "FlyweightA.h"
#include "FlyweightB.h"
#include "FlyweightFactory.h"
#include <memory>
#include <iostream>

using namespace npFlyweight;
using namespace std;


void doFlyweight()
{
    const FlyweightFactory& ff = FlyweightFactory::getInst();
    Flyweight& f0 = ff.getFlyweight(0);
    Flyweight& f1 = ff.getFlyweight(1);

    f0.operate(0);
    f0.operate(1);
    f0.operate(2);
    f1.operate(5);
    f1.operate(6);
    f1.operate(7);

    try
    {
        Flyweight& f2 = ff.getFlyweight(2);
    }
    catch(const out_of_range& e)
    {
        cerr << e.what() << endl;
    }
    catch(...)
    {
        cerr << "Uncaught error when acquiring flyweight." << endl;
    }
}